package heima.test.demo3;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception{
        // 1.解析字符串，产生Student 列表
        String info = "10001,张无忌,男,2023-07-22 11:11:12,东湖-黄鹤楼#10002,赵敏,女,2023-07-22 09:11:21,黄鹤楼-归元禅寺#10003,周芷若,女,2023-07-22 04:11:21,木兰文化区-东湖#10004,小昭,女,2023-07-22 08:11:21,东湖#10005,灭绝,女,2023-07-22 17:11:21,归元禅寺";

        String[] student_infos = info.split("#");
        List<Student> students = new ArrayList<>();
        for(String student_info: student_infos){
            String[] values = student_info.split(",");
            long id = Long.parseLong(values[0]);
            String name = values[1];
            String gender = values[2];
            LocalDateTime time = LocalDateTime.parse(values[3], DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
            List<String> list = new ArrayList<>(Arrays.asList(values[4].split("-")));
            Student student = new Student(id, name, gender, time, list);
            students.add(student);
        }

        // 2.统计景点次数
        Map<String, Integer> map = new HashMap<>();
        for(Student student: students){
            List<String> list = student.getList();
            for(String location: list){
                if(map.containsKey(location)){
                    map.put(location, map.get(location) + 1);
                } else {
                    map.put(location, 1);
                }
            }
        }
        System.out.println(map.toString());
        String target_location = null;
        int count = 0;
        for(String location: map.keySet()){
            if(map.get(location) > count){
                count = map.get(location);
                target_location = location;
            }
        }
        System.out.println("最热景点"+target_location+"次数为"+count);
        List<String> studentNotSelectTargetLocation = new ArrayList<>();
        for(Student student:students){
            List<String> list = student.getList();
            if(!list.contains(target_location)){
                studentNotSelectTargetLocation.add(student.getName());
            }
        }
        System.out.println(studentNotSelectTargetLocation + "没有选择最热的景点");

    }
}
